package com.burgeon.backend.SHOPBACKEND.rest;

import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.SHOP.entity.RefundErpVO;
import com.burgeon.backend.SHOPBACKEND.entity.YcVRetail;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

/*云仓派单未提交*/
public class QuerryYcVRetail extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public QuerryYcVRetail(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }


    /**
     * 发送并接收字符创
     * @return
     */

    public ArrayList<YcVRetail> getData() throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";
        String str = RESULT(Data(), url);
        //System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        if (!"0".equals(code)) {
            throw new Exception(str);
        }
        //System.err.println(str);
        String count = new JSONArray(str).getJSONObject(0).getString("count");
        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");

        ArrayList<YcVRetail> ycVRetails = new ArrayList<>();
        for (int i = 0;i<jsonArray.length();i++) {

            YcVRetail ycVRetail = new YcVRetail();
            ycVRetail.setId(jsonArray.getJSONArray(i).getString(0));
            ycVRetail.setDoNo(jsonArray.getJSONArray(i).getString(1));

            ycVRetails.add(ycVRetail);
        }

        return ycVRetails;
    }

    private MultiValueMap Data() {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段
        columns.add("ID");
        columns.add("DOCNO");//单据编号

        params.put("columns", columns);
        params.put("table", "YC_V_RETAIL");//表名

        params.put("count","true");

        HashMap paramss = new HashMap();

        String status = "'=1'";
        paramss.put("column", "STATUS");
        paramss.put("condition", status);

        params.put("params", paramss);
        //System.err.println(params);

        return DATA("Query", params,account,password);
    }

    public static void main(String[] args) {
        QuerryYcVRetail querryYCRetailout = new QuerryYcVRetail("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            System.err.println(querryYCRetailout.getData());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
